package com.cloud.cop.response;

import java.util.List;

import javax.xml.bind.annotation.XmlAccessType;
import javax.xml.bind.annotation.XmlAccessorType;
import javax.xml.bind.annotation.XmlAttribute;
import javax.xml.bind.annotation.XmlElement;
import javax.xml.bind.annotation.XmlElementWrapper;
import javax.xml.bind.annotation.XmlRootElement;

import com.cloud.cop.CopResponse;
import com.cloud.cop.validation.MainError;
import com.cloud.cop.validation.SubError;

/**
 * 用于返回错误信息
 * @author mayh
 *
 */
@XmlAccessorType(XmlAccessType.FIELD)
@XmlRootElement(name = "error")
public class ErrorCopResponse implements CopResponse {

    @XmlAttribute
    protected String code;

    @XmlAttribute
    protected String message;

    @XmlAttribute
    protected String solution;
	
    @XmlElementWrapper(name = "subErrors")
    @XmlElement(name = "subError")
    protected List<SubError> subErrors;
    
    public ErrorCopResponse(){
    	
    }
    
    public ErrorCopResponse(MainError mainError){
    	this.code = mainError.getCode();
    	this.message = mainError.getMessage();
    	this.solution = mainError.getSolution();
    	if(mainError.getSubErrors()!=null&&mainError.getSubErrors().size()>0){
    		this.subErrors = mainError.getSubErrors();
    	}
    }

	public String getCode() {
		return code;
	}

	public void setCode(String code) {
		this.code = code;
	}

	public String getMessage() {
		return message;
	}

	public void setMessage(String message) {
		this.message = message;
	}

	public String getSolution() {
		return solution;
	}

	public void setSolution(String solution) {
		this.solution = solution;
	}

	public List<SubError> getSubErrors() {
		return subErrors;
	}

	public void setSubErrors(List<SubError> subErrors) {
		this.subErrors = subErrors;
	}
	
	protected void setMainError(MainError mainError){
		this.code =  mainError.getCode();
		this.message = mainError.getMessage();
		this.solution = mainError.getSolution();
	}
}
